package longshu.data.service;

import longshu.data.common.BaseEntity;
import longshu.data.common.dao.BaseDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;

/**
 * BaseService
 *
 * @author LongShu 2018/01/22
 */
@Component
public abstract class BaseService<D extends BaseDao<E>, E extends BaseEntity> {
    protected Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired(required = false)
    protected D dao;

    public D getDao() {
        return dao;
    }

    //********************************************//

    @Transactional
    public int insert(E entity) {
        return dao.insert(entity);
    }

    @Transactional
    public int insertSelective(E entity) {
        return dao.insertSelective(entity);
    }

    @Transactional
    public int insertList(List<E> recordList) {
        return dao.insertList(recordList);
    }

    //********************************************//

    @Transactional
    public int delete(E entity) {
        return dao.delete(entity);
    }

    @Transactional
    public int deleteByKey(E entity) {
        return dao.deleteByPrimaryKey(entity);
    }

    //********************************************//

    @Transactional
    public int updateByKey(E entity) {
        return dao.updateByPrimaryKey(entity);
    }

    @Transactional
    public int updateByKeySelective(E entity) {
        return dao.updateByPrimaryKeySelective(entity);
    }

    //********************************************//

    public E selectOne(E entity) {
        return dao.selectOne(entity);
    }

    public List<E> select(E entity) {
        return dao.select(entity);
    }

    public List<E> selectAll() {
        return dao.selectAll();
    }

    public int selectCount(E entity) {
        return dao.selectCount(entity);
    }

    public E selectByKey(Serializable key) {
        return dao.selectByPrimaryKey(key);
    }

}
